Skip to content


ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  SITL  debug  rangefinder  pymavlink  mavros  gazebo  distance sensor  system_time  timesync  cmake  gtest  ctest  101  cpp  c++  format  fmt  multithreading  spdlog  cyclonedds  eprosima  fastdds  simulation  config  ignition  bridge  sdf  tips  ign-transport  camera  sensors  lidar  aptly  apt  repository  mirror  encryption  pgp  docker  nvidia  git  bundle  submodules  github  hooks  pre-commit  lxd  container  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  kml  python  geo  snippets  cheat Sheet  asyncio  future  click  cli  numpy  project  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  mock  iterator  generator  logging  tuple  namedtuple  typing  annotation  typever  pyzmq  zmq  msgpack  action  namespace  remap  control2  ros2_control  gdb  qos  tag  plugins  msg  node  zero-copy  shm  tutorial  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  rpi  arm  qemu  settings  behavior  py_trees  bt  behavior_trees  blackboard  plot  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  model  cook  gps  imu  ray  gazebo_ros_ray_sensor  ultrsonic  range  ultrasonic  gazebo classic  wrench  effort  odom  ign  gz  xacro  ros_ign  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  slam  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  deb  package  setup  local_setup  rosdep  package manager  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  cross-compiler  nano  texture  tmuxp  loop device  rootfs  embedded  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  udev  ip  ss  network  netstat  snap  deploy  ssh  systemd  socat  networking  serial  udp  tc  mtu  select  robotics  kalman_filter  kalman  filter  control  extensions  json  yaml  schema  yocto  poky  projects  courses to follow  world  gazebo_ros2_control  position_controller  effort_controller  velocity_controller  gazebo_ros_force  gazebo_ros_joint_state_publisher  joint_state_publisher  vrx  buoyancy 

udp big packet and MTU

Detect link MTU by send udp big packets


Code demo#

udp
#!/usr/bin/env python3
import socket

# Inlined constants, because Python 3.6 has dropped the IN module.
class IN:
    IP_MTU = 14
    IP_MTU_DISCOVER = 10
    IP_PMTUDISC_DO = 2

def send_big_datagram(host, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
    sock.connect((host, port))
    try:
        sock.send(b'#' * 1500)
    except socket.error as e:
        print(e)
        print('Alas, the datagram did not make it')
        max_mtu = sock.getsockopt(socket.IPPROTO_IP, IN.IP_MTU)
        print('Actual MTU: {}'.format(max_mtu))
    else:
        print('The big datagram was sent!')

if __name__ == '__main__':
    send_big_datagram("172.17.0.2", 1060)

Test#

  • Create ubuntu docker image with tcpdump and netcat
FROM ubuntu:20.04
RUN apt-get update && apt-get install --no-install-recommends --yes \
    tcpdump \
    net-tools \ 
    netcat
CMD ["/bin/sh"]

Test 1: Test 123#

  • Run docker image
  • Run tcpdump and sniff for icmp
  • Send ping from host machine
tcpdump -n -i eth0 icmp

Test 2: send udp packet less then MTU#

docker shell1
tcpdump -n -i eth0 udp and port 1060 or icmp
docker shell2
nc -ul 1060

Test 3: send udp packet bigger then MTU#

  • Run tcpdump and nc like in Test 2
  • send with sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
  • comment the above line
with IP_PMTUDISC_DO
python examples/python/networking/udp/big_Sender.py
# result
[Errno 90] Message too long
Alas, the datagram did not make it
Actual MTU: 1500

# packet not send at all
without setsockopt
python examples/python/networking/udp/big_Sender.py
# Host Result
The big datagram was sent!
# shell 1: tcpdump
19:11:06.400842 IP 172.17.0.1.47327 > 172.17.0.2.1060: UDP, bad length 1500 > 1472

# shell 2: nc
show 1500 char of '#'
19:14:46.502573 IP 172.17.0.2.1060 > 172.17.0.1.48321: UDP, length 1
19:14:46.502686 IP 172.17.0.1 > 172.17.0.2: ICMP 172.17.0.1 udp port 48321 unreachable, length 37
19:14:51.960248 IP 172.17.0.1.58025 > 172.17.0.2.1060: UDP, bad length 1500 > 1472